<template>
	<div class="bg-act-box">
		<el-dialog
		  :title="title"
		  :visible.sync="dialogVisible"
		  width="30%"
		  :before-close="handleClose">
			  <div class="o-u-box">
					<span class="m-s-txt-lb">马上抢:</span>
					<el-image
						  style="width: 100px; height: 100px"
						  :src="imgBtn"></el-image>
					<div class="u-btn" @click.stop="chooseImg(1)">+上传替换</div> 
			  </div>
			  <div class="o-u-box">
					<span class="m-s-txt-lb">抢光了:</span>
					<el-image
						  style="width: 100px; height: 100px"
						  :src="imgFinishBtn"></el-image>
					<div class="u-btn" @click.stop="chooseImg(2)">+上传替换</div> 
			  </div>
		</el-dialog>
	</div>
</template>

<script>
	import uploadPic from "@/js/upload/UploadPic.js";
	import staticConst from "@/js/const/StaticConst.js";
	export default
	{
		data()
		{
			return{
				title:"",
				dialogVisible:false,
				imgBtn:"",
				baseImgBtn:"",
				imgFinishBtn:"",
				baseImgFinishBtn:"",
				act:""
			}
		},
		
		methods:
		{
			showWin(data)
			{
				this.dialogVisible = true;
				this.title = "活动产品购买按钮图片设置";
				this.act = data.act;
				this.imgBtn = data.data.imgBtn;
				this.baseImgBtn = data.data.baseImgBtn;
				this.imgFinishBtn = data.data.imgFinishBtn;
				this.baseImgFinishBtn = data.data.baseImgFinishBtn;
			},
			
			handleClose()
			{
				this.dialogVisible = false;
			},
			
			chooseImg(type)
			{
				let that = this;
				uploadPic.idyun = 22;
				uploadPic.activeId = 1;
				uploadPic.type = staticConst.UPLOAD_INTER_ACTIVE;
				uploadPic.uploadSussecc = uploadSuccess;
				uploadPic.chooseImage1(callBack);
				function callBack(data)
				{
					if(type == 1)
					{
					  that.imgBtn = data.url;  //显示图片
					}
					else if(type == 2)
					{
						that.imgFinishBtn = data.url;
					}
				}
				
				function uploadSuccess(data)
				{
					let obj = {};
					obj.act = that.act;
					obj.data = {};
					if(type == 1) //抢光了
					{
						that.imgBtn = obj.data.imgBtn = data.url;
						obj.data.baseImgBtn = data.name;
						obj.data.imgFinishBtn = that.imgFinishBtn;
						obj.data.baseImgFinishBtn = that.baseImgFinishBtn;
					}
					else if(type == 2)
					{
						obj.data.imgBtn = that.imgBtn;
						obj.data.baseImgBtn = that.baseImgBtn;
						that.imgFinishBtn = obj.data.imgFinishBtn = data.url;
						obj.data.baseImgFinishBtn = data.name;
					}
					that.$emit("editBuyGdsImg",obj);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.bg-act-box
	{
		::v-deep.el-dialog
		{
			margin-top: 40vh !important;
		}
	}
	
	.m-s-txt-lb
	{
		padding-right: 10px;
	}
	.o-u-box
	{
		display:flex;
		align-items: center;
		padding-top: 20px;
		.u-btn
		{
			margin-left: 10px;
			padding: 4px 20px;
			background-color: #3388FF;
			color:#FFF;
			border-radius: 4px;
			cursor: pointer;
		}
	}
	
</style>